package com.suny.sf_server.controller;

import com.suny.DataDic.dto.DataDicQueryDTO;
import com.suny.DataDic.dto.DataDicUpdateStatusDTO;
import com.suny.DataDic.vo.DataDicVO;
import com.suny.result.PageDTO;
import com.suny.sf_server.service.DataDicService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.suny.DataDic.dto.DataDicDTO;
import com.suny.result.R;

import java.util.List;

@Slf4j
@Tag(name = "数据字典", description = "数据字典相关接口")
@RestController
@RequestMapping("/dataDic")
public class DataDicController {
    @Resource
    private DataDicService dataDicService;
    @Operation(summary = "新增数据字典")
    @PostMapping("/add")
    public R addDataDic(@Validated @RequestBody DataDicDTO dataDicDTO){
        Boolean result=dataDicService.addDataDic(dataDicDTO);
        return result?R.OK( "添加成功"):R.FAIL( "添加失败");
    }
    @Operation(summary = "查询数据字典")
    @GetMapping("/list")
    public R getDataDic(){
        List<DataDicVO> dataDicVO=dataDicService.getBySelect();
        return R.OK(dataDicVO);
    }
    @Operation(summary = "修改数据字段状态")
    @PostMapping("/updateStatus")
    public R updateStatus(@Validated @RequestBody DataDicUpdateStatusDTO dto){
        Integer id=dto.getId();
        Integer status=dto.getStatus();
        Boolean result=dataDicService.updateStatus(id,status);
        return result?R.OK( "修改成功"):R.FAIL( "修改失败");
    }
    @Operation(summary = "条件查询数据字典")
    @PostMapping("/getDataDicByCondition")
    public R getDataDicByCondition(@RequestBody DataDicQueryDTO dataDicQueryDTO){
        return R.OK(dataDicService.getListByCondition(dataDicQueryDTO));
    }
}
